package edu.jit.flowers.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import edu.jit.flowers.bean.Orders;
import edu.jit.flowers.bean.Users;
import edu.jit.flowers.service.OrdersService;
import edu.jit.flowers.service.UsersService;
import edu.jit.flowers.utils.BaseServlet;

public class OrdersServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	private OrdersService oService = new OrdersService();	
	private UsersService uService = new UsersService();	
	//管理员查看所有订单  
	public String getAllOrders(HttpServletRequest request, HttpServletResponse response) {
    	List<Orders> orders = oService.getAllOrders();
    	request.setAttribute("orders", orders);
    	return "forword:backJsp/orderShow.jsp";
    }
    //ouName如何获取 跟据当前session里面的name可以获取到吗？
    public void addOrders(HttpServletRequest request, HttpServletResponse response) {
		String ouName = (String) request.getSession().getAttribute("username");
		Users u = uService.getAllCommonsByUName(ouName);
		double oTotal = Double.parseDouble(request.getParameter("oTotal"));
		String oComment = request.getParameter("oComment");
		String oStatus = request.getParameter("oStatus");
		oService.addOrders(new Orders(0,u.getuId(),ouName,oTotal,null,oComment,oStatus));
		//return "";
    }
    //用户查看自己的订单
    public String getOrdersByouName(HttpServletRequest request, HttpServletResponse response) {
    	String ouName = request.getParameter("ouName");
    	List<Orders> orders = oService.getAllOrdersByUName(ouName);
    	request.setAttribute("orders", orders);
    	return "forword:orderList.jsp";
    }
   
}
